{% template "common/header" . %}
    <div class="ui small modal">
        <div class="header">用户登录</div>
        <div class="content">
            <form class="ui form">
                <div class="two fields">
                    <div class="field">
                        <input class="small input" type="text" name="username" placeholder="用户名或邮箱">
                    </div>
                </div>
                <div class="two fields">
                    <div class="field">
                        <input type="password" name="password" placeholder="密码">
                    </div>
                </div>
                <div class="two fields">
                    <div class="field">
                        {%.Captcha.CreateHtml%}
                        <input type="text" name="captcha" placeholder="验证码">
                    </div>
                </div>
                <button class="ui button primary button" >登录</button>
            </form>
        </div>
    </div>

<script type="text/javascript">
    $('.ui.modal').modal('setting', 'closable', false).modal('show');
    $('.ui.form').form(
            {
                onSuccess: function(event, fields) {
                    util.post('/user/login', fields, function(code, message) {
                        location.href = "/"
                    }, function (code, message) {
                        if (code == 5) {
                            $('.captcha-img').trigger('click');
                        }
                    });

                    return false;
                },
                fields: {
                    username: {
                        identifier  : 'username',
                        rules: [
                            {
                                type   : 'empty',
                                prompt : '请输入用户名'
                            }
                        ]
                    },
                    Password: {
                        identifier  : 'password',
                        rules: [
                            {
                                type   : 'empty',
                                prompt : '请输入密码'
                            }
                        ]
                    },
                    Captcha: {
                        identifier  : 'captcha',
                        rules: [
                            {
                                type   : 'empty',
                                prompt : '请输入验证码'
                            }
                        ]
                    }
                },
                inline : true
            });
</script>
{% template "common/footer" . %}